<template>
	<vk-data-dialog
		v-model="value.show"
		:title="page.title"
		:top="page.top"
		:width="page.width"
		:close-on-click-modal="true"
		mode="form"
		@open="onOpen"
		@closed="onClose"
	>
		<!-- 页面主体内容开始 -->
		<vk-data-form
			ref="form1"
			v-model="form1.data"
			:form-type="value.mode"
			:rules="form1.props.rules"
			:action="form1.props.action"
			:columns="form1.props.columns"
			:loading.sync="form1.props.loading"
			:labelWidth="form1.props.labelWidth"
			:show-cancel="page.showCancel"
			:cancel-text="page.cancelText"
			:submit-text="page.submitText"
			@success="onFormSuccess"
		></vk-data-form>
		<!-- 页面主体内容结束 -->
	</vk-data-dialog>
</template>

<script>
var that; // 当前页面对象
var vk = uni.vk; // vk实例
var typeData = vk.getVuex('$app.config.maill.coupon.type');
export default {
	props: {
		value: {
			Type: Object,
			default: function() {
				return {
					show: false,
					mode: "",
					item: {}
				};
			}
		}
	},
	data: function() {
		// 组件创建时,进行数据初始化
		return {
			page: {
				title: "标题",
				submitText: "确定",
				cancelText: "关闭",
				showCancel: true,
				top: "7vh",
				width: "800px"
			},
			form1: {
				// 表单请求数据，此处可以设置默认值
				data: {},
				// 表单属性
				props: {
					// 表单请求地址
					action: "admin/business/sys/coupon.giveCoupon",
					// 表单字段显示规则
					columns: [
						{ key:"name", title:"优惠券标题", type:"text-view" },
						{ key:"coupon_rule_msg", title:"优惠内容", type:"text-view" },
						{
							key: "user_id", title: "用户", type: "table-select", placeholder:"请选择赠送的用户",
							action:"admin/business/sys/user.getList",
							multiple: true,
							// formData:{
							// 	is_fx:1
							// }, 
							columns:[
								{ key:"avatar", title:"头像", type:"avatar", width:60 },
								{ key:"nickname", title:"昵称", type:"text", nameKey:true },
								{ key:"mobile", title:"手机", type:"text" },
								{ key:"comment", title:"备注", type:"text" },
								{ key:"_id", title:"角色标识", type:"text", idKey:true, show:["none"] }, // idKey:true 代表此字段为主键字段，若设置show:["none"],则可以在表格中隐藏该字段的显示
							],
							queryColumns:[
								{ key:"nickname", title:"昵称", type:"text", width:160, mode:"%%" },
								{ key:"mobile", title:"手机号", type:"text", width:160, mode:"%%", lastWhereJson: true },
								{ key:"comment", title:"备注", type:"text", width:160, mode:"%%" },
								// { key:"is_fx", title:"状态", type:"number", width:160, mode:"=", fieldName:"fx.is_fx", show:["none"] },
							],
							disabled:["update"]
						},
						{ key:"num", title:"赠送数量", type:"number",width:160, rightText:"张", clearable:false }
					],
					// 表单验证规则
					rules: {

					},
					// 左侧label的宽度
					labelWidth: "120px",
				}
			}
		};
	},
	mounted() {
		that = this;
		that.init();
	},
	methods: {
		// 初始化
		init() {
			let { value } = that;
			that.$emit("input", value);
		},
		// 监听 - 页面打开
		onOpen() {
			that = this;
			let { item={} } = that.value;
			// 每次打开时，重新设置表单的值 = value.item 的值，item通过 vk.pubfn.openForm('表单名',{ item:{ _id:"1" } }) 传递值
			that.form1.data = {
				_id: item._id,
				name: item.name,
				coupon_rule_msg: item.coupon_rule_msg,
				user_id: "",
				num: 1
			}
		},
		// 监听 - 页面关闭
		onClose() {
			//that.$refs.form1.resetForm(); // 关闭时，重置表单
		},
		// 监听 - 提交成功后
		onFormSuccess() {
			that.value.show = false; // 关闭页面
			that.$emit("success");
		}
	},
	watch: {

	},
	// 计算属性
	computed: {

	}
};
</script>

<style lang="scss" scoped></style>
